﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml.Serialization;
using System.Windows.Forms;
using Snefru.Managers;

namespace Snefru.XmlObjects
{
    [Serializable()]
    [XmlRoot("SnefruQuerySettings")]
    public class SnefruQuerySettings : XmlOperationManager<SnefruQuerySettings>
    {
        public static string XmlPath = Application.StartupPath.Replace("\\bin\\Debug", "") + @"\XML\SnefruQuerySettings.xml";

        [XmlArray]
        [XmlArrayItem("DatabaseInstance", typeof(DatabaseInstance))]
        public List<DatabaseInstance> DatabaseInstances { get; set; }
    }

    [Serializable()]
    public class DatabaseInstance
    {
        [XmlAttribute]
        public string Type { get; set; }

        [XmlAttribute]
        public int ID { get; set; }

        [XmlArray]
        [XmlArrayItem("InjectionQuery", typeof(InjectionQuery))]
        public List<InjectionQuery> InjectionQueries { get; set; }

        [XmlElement]
        public ConfirmationQuery ConfirmationQuery { get; set; }

        [XmlElement]
        public AttackingQuery AttackingQuery { get; set; }
    }

    [Serializable()]
    public class InjectionQuery
    {
        [XmlElement]
        public int InjectionQueryID { get; set; }

        [XmlElement]
        public string Name { get; set; }

        [XmlElement]
        public string Query { get; set; }

        [XmlElement]        
        public TableQuery TableQuery { get; set; }        
    }

    [Serializable()]
    public class TableQuery
    {
        [XmlElement]
        public string TableCountQuery { get; set; }

        [XmlElement]
        public string TableNameQuery { get; set; }
    }

    [Serializable()]
    public class ConfirmationQuery
    {
        [XmlElement]
        public string Query { get; set; }
    }

    [Serializable()]
    public class AttackingQuery
    {
        [XmlElement]
        public string QueryLenght { get; set; }

        [XmlElement]
        public string QueryCount { get; set; }
        
        [XmlElement]
        public string Query { get; set; }

        [XmlArray]
        [XmlArrayItem("QueryType", typeof(QueryType))]
        public List<QueryType> QueryTypes { get; set; }
    }

    [Serializable()]
    public class QueryType
    {
        [XmlElement]
        public int AttackID { get; set; }

        [XmlElement]
        public string AttackName { get; set; }

        [XmlElement]
        public string QueryPrefix { get; set; }

        public bool IsVulnerable { get; set; }
    }
}
